package huawei_nowcoder;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @Description: 学英语
 * @Date: 2020/4/24
 * @Author: 许群星
 */
public class LearnEnglish_1 {
    /*
    0-9
     */
    static String[] nums1 = {
            "zero", "one", "two", "three", "four"
            , "five", "six", "seven", "eight", "nine"};
    /**
    10-19
     */
    static String[] nums2 = {
            "ten", "eleven", "twelve", "thirteen", "fourteen"
            , "fifteen", "sixteen", "seventeen", "eighteen", "nighteen"};
    /**
     * 20-90
     */
    static String[] nums3 = {"twenty", "thirty", "forty", "fifty"
            , "sixty", "seventy", "eighty", "ninety"};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            long a = sc.nextLong();
            System.out.println(convertEnglish(a));
        }
    }

    //数字转英语
    public static String convertEnglish(long a) {
        //每部分不过千，所以每三位处理一下
        if (a<0) {
            return "error";
        }
        StringBuilder sb=new StringBuilder();
        //十亿
        long billion=a/1000000000;
        if (billion!=0){
            sb.append(thranslate(billion)+" billion ");
        }
        a%=1000000000;
        //百万
        long million=a/1000000;
        if (million!=0){
            sb.append(thranslate(million)+" million ");
        }
        a%=1000000;
        //千
        long thousand=a/1000;
        if (thousand!=0){
            sb.append(thranslate(thousand)+" thousand ");
        }
        a%=1000;
        //白
        if (a!=0){
            sb.append(thranslate(a));
        }
        return sb.toString().trim();

    }
    //翻译
    public static String thranslate(long num){
        StringBuilder sb=new StringBuilder();
        //百位处理
        long h=num/100;
        if (h!=0){
            sb.append(nums1[(int)h]+" hundred");
        }
        num%=100;
        //十位
        long k=num/10;
        if (k!=0){
            if (h != 0) {
                sb.append(" and ");
            }
            if (k == 1) {
                long t=num%10;
                sb.append(nums2[(int)t]);
            }else {
                sb.append(nums3[(int)k-2]+" ");
                if (num % 10 != 0) {
                    sb.append(nums1[(int)(num%10)]);
                }
            }
        } else if (num % 10 != 0) {
            if (h != 0) {
                sb.append(" and ");
            }
            sb.append(nums1[(int)(num%10)]);
        }
        return sb.toString().trim();
    }

}
/*
题目描述
Jessi初学英语，为了快速读出一串数字，编写程序将数字转换成英文：
如22：twenty two，123：one hundred and twenty three。
说明：
数字为正整数，长度不超过九位，不考虑小数，转化结果为英文小写；
输出格式为twenty two；
非法数据请返回“error”；
关键字提示：and，billion，million，thousand，hundred。
方法原型：public static String parse(long num)
输入描述:
输入一个long型整数
输出描述:
输出相应的英文写法
示例1
输入
复制
2356
输出
复制
two thousand three hundred and fifty six
 */